package com.xianggu.service;

import com.xianggu.common.XiangGuService;
import com.xianggu.demo.dto.UserDto;
import com.xianggu.mapper.UserMapper;
import com.xianggu.mybatis.paging.Page;
import com.xianggu.spring.annotation.AutoWired;
import com.xianggu.spring.annotation.Service;
import com.xianggu.spring.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @author chengjy
 * @date 2025/3/8
 */
@Service
public class XiangGuServiceImpl implements XiangGuService {
    @AutoWired
    private UserMapper userMapper;

    @Override
    public String doService(String text) {
        return text + "  服务端响应：香菇是个大坏蛋？！";
    }

    @Override
    public UserDto getUserInfo(String id) {
//        return new UserDto(id, "吃喝嫖赌", "烧杀抢掠","香菇大魔头");
        return userMapper.getUserInfo(id);
    }

    @Override
    public List<UserDto> queryUserList(String condition) {
//        return Arrays.asList(new UserDto("1", "吃喝嫖赌", "烧杀抢掠","香菇大魔头") ,
//                new UserDto("2", "尊老爱幼", "喜欢少妇","香菇左护法"),
//                new UserDto("3", "欺男霸女", "尊师重道","香菇右护法"));
        return userMapper.quertList(condition);
    }

    @Override
    @Transactional
    public String saveUser(UserDto userDto) {
        String result = userMapper.saveUser(userDto);
//        throw new RuntimeException("服务器不小心不小心了！");
        return result;
    }

    @Override
    public Page<UserDto> getUserList(String id, int pageNum, int pageSize) {
        Page<UserDto> page = new Page<>(pageNum, pageSize);
        Page<UserDto> userList = userMapper.getUserList(id, page);
        return userList;
    }

    @Override
    public List<Map<String, Object>> getUserListMap(String id, int pageNum, int pageSize) {
        return userMapper.getUserListMap(id);
    }

    @Override
    public Page<UserDto> getInitList(int pageNum, int pageSize) {
        return userMapper.getInitList(new Page<UserDto>(pageNum, pageSize));
    }

    @Override
    public UserDto getUserById(String id) {
        if(!"".equals( id) && id != null){
            return userMapper.getUserById(id);
        }
        return null;
    }

    @Override
    public String updateById(UserDto userDto) {
        return userMapper.updateById(userDto);
    }

    @Override
    public Page<UserDto> searchContidion(Map<String, Object> param) {
        Page<UserDto> page = new Page<>((Integer) param.get("pageNum"), (Integer) param.get("pageSize"));
        return userMapper.searchContidion(page ,param);
    }

    @Override
    public String deleteById(String id) {
        return userMapper.deleteById(id);
    }
}
